package com.itheima;

import java.util.*;

/**
 * @ProjectName: ybxy6
 * @Titile: CollectionsDemo
 * @Author: 86183
 * @Description: TODO
 * 演示Collections工具类使用
 */
public class CollectionsDemo {
    public static void main(String[] args) {
        test1();
}

    public static void test0(String[] args) {
        List<String> list = new LinkedList<>();
        Collections.addAll(list,"马林","坎特雷拉","长离","公孙离");
        //实际顺序
        list.forEach(System.out::println);
        System.out.println("--------------------------------");
        //打乱
        Collections.shuffle(list);
        list.forEach(System.out::println);
    }
    public static synchronized void test1(){
        List<Integer> list = new ArrayList<>();
        Collections.addAll(list,1,2,3,4,5,6,7,8,9,10);
        Collections.sort(list);
        list.forEach(System.out::println);
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2 - o1;//倒序
            }
        });
        System.out.println("--------------------------------");
        list.forEach(System.out::println);
        //Colletions排序功能
        List<Student>list1 = new ArrayList<>();
        list1.add(new Student("马林",20));
        list1.add(new Student("坎特雷拉",19));
        list1.add(new Student("长离",23));
        list1.add(new Student("公孙离",21));
        Collections.sort(list1);
        list1.forEach(System.out::println);
        //不安全、效率高
        /*List<Integer> synchrenizedList = Collections.synchronizedList(list);
*/
    }

}
